<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>todo list</title>
  </head>
  <body>
    <script src="https://unpkg.com/vue@next"></script>

    <div id="root"></div>

    <script>
      const app = Vue.createApp({
        data() {
          return {
            list: [],
            inputValue: "",
          };
        },
        methods: {
          hanleAddItem() {
            this.list.push(this.inputValue);
            this.inputValue = "";
          },
        },
        template: `
                   <ul>
                        <input type="text" v-model="inputValue">
                        <button v-on:click="hanleAddItem" v-bind:title="inputValue">增加</button>
                        <todo-item
                        v-for="(item, index) of list"
                        v-bind:content="item"
                        v-bind:index="index"
                        
                        />  
                    <ul>       
               `,
      });

      app.component("todo-item", {
        props: ["content", "index"],
        template: `<li>{{content}} --- {{index}}</li>`,
      });

      app.mount("#root");
    </script>
  </body>
</html>
